<?php

namespace app\home\controller;

use cmf\controller\HomeBaseController;

use app\home\controller\UserController;

use app\home\model\UsersModel;

use app\home\model\LessonModel;

use app\home\model\LessonNameModel;

use app\home\model\SchoolModel as School;

use think\Db;



class IndexController extends UserController

{



	//展示所有课程

	public function index()

	{


		return $this->fetch();

	}

	public function getSchoolList(){
		if($_SERVER['REQUEST_METHOD']=="POST"){
		
		$name = $_POST['name'];
		$data['names'] = Db::name('school')
   		->where('name','like',"%$name%")
    	->select();
		$this->success('1','',$data);
	}
	}

	// public function getSchoolList(School $School){
	// 	$name = $this->request->param('name');
		
		
	// 	if ($name) {
	// 		$where['name'] = ['like',"%$name%"];
	// 		$data['names'] = $School->getList($where);

	// 	}else{
	// 		$data['names'] = array();
	// 	}
	// 	$this->success('1','',$data);
	// }





	//默认展示所选学校当天，一年级，一班课程

	public function details()

	{



				$id = $this->request->param('id');

				//查询搜索的学校名称

				$names = Db::name('school')->where('id',$id)->find();
				$name = mb_substr($names['name'],0,13,"utf-8");

				if ($name) {

					$this->assign('names',$names);
					$this->assign('name',$name);

				}



				//所有课程名

				$lessons = Db::name('lessonName')->select();



				if ($lessons) {

					$this->assign('lessons',$lessons);

				}





		

		return $this->fetch();

	



}

	//按条件展示课程数据

	public function sousou()

	{

		$lesson = new LessonModel();



		if($_SERVER['REQUEST_METHOD']=="POST"){

			$id = $this->request->param('id');

			$date = $this->request->param('date');

			$grade = $this->request->param('grade');

			$ban = $this->request->param('ban');



			$data['lessonNames'] = Db::name('lesson')->where('school_id',$id)->where('grade',$grade)->where('class',$ban)->where('day',$date)->select()->toArray();

			$data['lessons'] = Db::name('lessonName')->select();
			

	 		$this->success('ww','',$data);

 		}

	}



	//修改搜索的数据

	public function page()

	{

		$lesson = new LessonModel();



		if($_SERVER['REQUEST_METHOD']=="POST"){

		$wan = $this->request->param();

		$ssid = $this->request->param('ssid');
		
		if ($wan['leid']) {

			

			$list = [

   	 	['lesson_id'=>$wan['leid'],'name'=>$wan['ssid'],'name_id'=>$wan['ssids']],

    	['lesson_id'=>$wan['leid1'],'name'=>$wan['ssid1'],'name_id'=>$wan['ssids1']],

    	['lesson_id'=>$wan['leid2'],'name'=>$wan['ssid2'],'name_id'=>$wan['ssids2']],

    	['lesson_id'=>$wan['leid3'],'name'=>$wan['ssid3'],'name_id'=>$wan['ssids3']],

    	['lesson_id'=>$wan['leid4'],'name'=>$wan['ssid4'],'name_id'=>$wan['ssids4']],

    	['lesson_id'=>$wan['leid5'],'name'=>$wan['ssid5'],'name_id'=>$wan['ssids5']],

    	['lesson_id'=>$wan['leid6'],'name'=>$wan['ssid6'],'name_id'=>$wan['ssids6']],

    	['lesson_id'=>$wan['leid7'],'name'=>$wan['ssid7'],'name_id'=>$wan['ssids7']]

				];

		$wans = $lesson->saveAll($list);



		if ($wans){

			$this->success('提交成功');

				}

		}else{

			

		$this->error('提交失败');

		

			}

		   }

		 }

		
		//添加课程
		public function pages()

		{

		$lesson = new LessonModel();



		if($_SERVER['REQUEST_METHOD']=="POST"){

		$wan = $this->request->param();

		
		$list = [
	    ['school_id'=>$wan['id'],'grade'=>$wan['grade'],'class'=>$wan['ban'],'begin_time'=>'09:00:00','end_time'=>'09:40:00','name_id'=>$wan['ssids'],'name'=>$wan['ssid'],'day'=>$wan['date'],'create_time'=>date('Y-m-d H:i:s',time())],
	    ['school_id'=>$wan['id'],'grade'=>$wan['grade'],'class'=>$wan['ban'],'begin_time'=>'09:45:00','end_time'=>'10:25:00','name_id'=>$wan['ssids1'],'name'=>$wan['ssid1'],'day'=>$wan['date'],'create_time'=>date('Y-m-d H:i:s',time())],
	    ['school_id'=>$wan['id'],'grade'=>$wan['grade'],'class'=>$wan['ban'],'begin_time'=>'10:30:00','end_time'=>'11:05:00','name_id'=>$wan['ssids2'],'name'=>$wan['ssid2'],'day'=>$wan['date'],'create_time'=>date('Y-m-d H:i:s',time())],
	    ['school_id'=>$wan['id'],'grade'=>$wan['grade'],'class'=>$wan['ban'],'begin_time'=>'13:30:00','end_time'=>'14:10:00','name_id'=>$wan['ssids3'],'name'=>$wan['ssid3'],'day'=>$wan['date'],'create_time'=>date('Y-m-d H:i:s',time())],
	    ['school_id'=>$wan['id'],'grade'=>$wan['grade'],'class'=>$wan['ban'],'begin_time'=>'14:15:00','end_time'=>'15:05:00','name_id'=>$wan['ssids4'],'name'=>$wan['ssid4'],'day'=>$wan['date'],'create_time'=>date('Y-m-d H:i:s',time())],
	    ['school_id'=>$wan['id'],'grade'=>$wan['grade'],'class'=>$wan['ban'],'begin_time'=>'15:10:00','end_time'=>'16:00:00','name_id'=>$wan['ssids5'],'name'=>$wan['ssid5'],'day'=>$wan['date'],'create_time'=>date('Y-m-d H:i:s',time())],
	    ['school_id'=>$wan['id'],'grade'=>$wan['grade'],'class'=>$wan['ban'],'begin_time'=>'16:05:00','end_time'=>'16:45:00','name_id'=>$wan['ssids6'],'name'=>$wan['ssid6'],'day'=>$wan['date'],'create_time'=>date('Y-m-d H:i:s',time())],
	    ['school_id'=>$wan['id'],'grade'=>$wan['grade'],'class'=>$wan['ban'],'begin_time'=>'16:50:00','end_time'=>'17:30:00','name_id'=>$wan['ssids7'],'name'=>$wan['ssid7'],'day'=>$wan['date'],'create_time'=>date('Y-m-d H:i:s',time())]
		];
		$wans = $lesson->saveAll($list);


		if ($wans){

			$this->success('提交成功');

				}

		

		   }

		 }

		



}